/*
 * @Date: 2023-03-10 19:41:16
 * @LastEditTime: 2023-03-10 21:10:55
 * @FilePath: /hash-guess-game/src/api/module/hashRaceCourse.ts
 * 介绍:哈希赛池
 */
import { defaHttp, Paging, ApiRes, ApiReturn } from "../index";

/**分享卡状态 */
export async function apiShareCard(): ApiReturn<ShareCard.Res> {
  const res = await defaHttp.post<ApiRes<ShareCard.Res>>(
    "/get/share/status",
    undefined,
    {
      mode: ["showError"],
    }
  );
  if (res.code !== 200) return;
  return res.data;
}

/**分享卡状态 */
export namespace ShareCard {
  export interface Res {
    /**0不可以购买；1可以购买 */
    status: 0;
    /**我的分享卡数量 */
    cards: 0;
  }
}
/**取消分享卡 */
export async function apiUnShareCard(data: UnShareCard.Req): ApiReturn<true> {
  const res = await defaHttp.post<ApiRes<UnShareCard.Res>>(
    "/cancel/share/card",
    data,
    {
      mode: ["showError", "showSucceed", "showLoading"],
    }
  );
  if (res.code !== 200) return;
  return true;
}

/**取消分享卡 */
export namespace UnShareCard {
  export interface Req {
    /**取消数量 */
    number: number;
  }
  export type Res = void;
}

/**分享卡操作记录 */
export async function apiShareCardLogs(
  formData: Paging.Req
): ApiReturn<Paging.Data<ShareCardLogs.ResItem[]>> {
  const res = await defaHttp.post<Paging.Res<ShareCardLogs.ResItem[]>>(
    "/buy/share/cardslogs",
    formData,
    { mode: ["showError"] }
  );

  if (res.code !== 200) return;
  return res.data;
}
/**分享卡操作记录 */
export namespace ShareCardLogs {
  export interface ResItem {
    id: Id;
    user_id: Id;
    /**购买数量 */
    number: StrNumber;
    /**0确认中；1：成功；2：失败 */
    status: number;
    created_at: string | Date;
    updated_at: string | Date;
    /**交易标识 */
    txid: string;
    from: null | string;
    to: null | string;
    type: number;
    actual_amount: number;
    remark: null | unknown;
  }
}
